/*
 * OpenFileAction.java
 *
 * Created on March 7, 2005, 11:29 AM
 */
package com.bff.slimserver.musicjukebox.lib.actions;

import com.bff.bjj.utils.Resources;
import com.bff.bjj.utils.Utils;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.io.File;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JFileChooser;
import javax.swing.JTextArea;

/**
 *
 * @author bill
 */
public class OpenTabAction extends AbstractAction {

    private File file;
    private Component parent;
    private JFileChooser fc;
    private JTextArea textArea;

    public OpenTabAction(Component parent, JTextArea textArea) {
        super(Resources.getMessage(Resources.LABEL_KEY.ACTION_OPEN_TAB_NAME));
        this.textArea = textArea;
        this.parent = parent;
        this.fc = new JFileChooser();

        fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
        putValue(Action.SMALL_ICON, Resources.getIcon(Resources.ICON_KEY.ACTION_OPEN_TAB));
    }

    @Override
    public void actionPerformed(ActionEvent actionEvent) {
        int returnVal = fc.showOpenDialog(parent);

        //Query the JFileChooser to get the input from the user
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            file = fc.getSelectedFile();
            Utils.readFile(textArea, file);
        }
    }
};
